package com.pignest.hotel.system;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

import com.pignest.hotel.annotation.Configuration;
import com.pignest.hotel.beans.User;
import com.pignest.hotel.beans.global.Menu;
import com.pignest.hotel.spring.Services;


/** zk前台调用  */
public class Global {

	public static final String IMAGE_PATH_ROOM_STATUS = "/images/roomview/";
	
	/** 入住流水号 */
	public static  synchronized String getLivineSerialNumber() {
		return "7H" + System.currentTimeMillis();
	}
	
	public static List<Menu> getMainMenus() {
		User user = Hotel.getCurrentUser();
		return Services.getMenuLoader().getMainMenus(user);
	}
	
	/** 基本设置项 */
	public static List<Menu> getSettingMenus() {
		User user = Hotel.getCurrentUser();
		if (user == null)
			return null;
		return Services.getMenuLoader().getSettingMenus(user);
	}
	
	/**
	 * 系统管理项
	 * */
	public static List<Menu> getAdminMenus() {
		User user = Hotel.getCurrentUser();
		if (user == null)
			return null;
		return Services.getMenuLoader().getAdminMenus(user);
	}
	
	public static List<Menu> getReportMenus() {
		User user = Hotel.getCurrentUser();
		if (user == null)
			return null;
		return Services.getMenuLoader().getReportMenus(user);
	}
	
	/** 性别 */
	public static String[] getGenders() {
		return new String[] {"男", "女"};
	}
	
	private static final String[][] COLORS = {
		{"红色", "FF0000"},
		{"紫色", "800080"},
		{"蓝色", "0000FF"},
		{"绿色", "008000"},
		{"橙色", "FFA500"},
		{"黄色", "FFFF00"},
		{"粉色", "FF0080"},
		
		{"金色", "FFD700"},
		{"青色", "00FFFF"},
		{"灰色", "808080"},
		{"银色", "C0C0C0"},
		{"褐色", "A52A2A"},
		{"春绿色", "00FF7F"},
		{"印第安红", "CD5C5C"},
		{"军兰色", "5F9EA0"},
		{"橄榄色", "808000"},
		{"黑色", "000000"},
		{"白色", "FFFFFF"},
	};
	public static String[][] getColors() {
		return COLORS ;
	}
	
	public static String getColorName(String color) {
		for (int i = 0; i < COLORS.length; i++) {
			if (COLORS[i][1].equals(color))
				return COLORS[i][0];
		}
		return color;
	}
	
	/** 证件类型 */
	public static String[] getPassportTypes() {
		return new String[] {
				"身份证"
				, "学生证"
				, "军官证"
				, "驾驶证"
				, "其它"
		};
	}
	
	/**
	 * 收款/支付方式
	 * */
	public static String[] getPaymentMethods() {
		return new String[] {
			"现金",
			"会员卡"
			, "银行借记卡"
			, "信用卡"
			, "支票"
			, "其它"
		};
	}
	/**
	 * 赔偿原因
	 * */
	public static String[] getPayReason() {
		return new String[] {
			"损坏"
			, "丢失"
			, "其它"
		};
	}
	/**
	 * 换房原因
	 * */
	public static String[] getChangeRoomReason() {
		return new String[] {
			  "正常换房"
			, "工程维修"
			, "其它"
		};
	}
	/** 一天中的时间节点 */
	public static String[] getTimes() {
		return new String[] {
			"00:00", "01:00", "02:00", 
			"03:00", "04:00", "05:00", 
			"06:00", "07:00", "08:00", 
			"09:00", "10:00", "11:00", 
			"12:00", "13:00", "14:00", 
			"15:00", "16:00", "17:00", 
			"18:00", "19:00", "20:00", 
			"21:00", "22:00", "23:00", 
		};
	}
	
	
	public static List<String[]> getConfigs() {
		List<String[]> configs = new ArrayList<String[]>(20);
		Method[] methods = Config.class.getDeclaredMethods();
		for (int i = 0; i < methods.length; i++) {
			Method m = methods[i];
//			if (!m.isAccessible())
//				continue;
			if ((m.getModifiers() & Modifier.PUBLIC) == 0)
				continue;
			if ((m.getModifiers() & Modifier.STATIC) == 0)
				continue;
			if (!m.isAnnotationPresent(Configuration.class))
				continue;
			if (m.getParameterTypes().length != 0)
				continue;
			Annotation[] as = m.getAnnotations();
			for (int j = 0; j < as.length; j++) {
				if (as[j] instanceof Configuration) {
					Configuration c = (Configuration)as[j];
//					if (!c.single())
//						continue;
					String key = c.key();
					Object value;
					try {
						value = String.valueOf(m.invoke(null));
					} catch (Exception e) {
						continue;
					}
					String desc = c.desc();
					a(configs, key, String.valueOf(value), desc, c.single());
					break;
				}
			}
		}
//		a(configs, Key.HOTEL_NAME, 			"酒店名称");
//		a(configs, Key.HOTEL_PHONE, 		"酒店电话");
//		a(configs, Key.DEFAULT_PASSWORD, 	"员工默认密码");
//		a(configs, Key.LINE_CAPACITY_SELF_SERVICE, 	"自助系统中选房时每行显示的房间数量");
//		a(configs, Key.LINE_CAPACITY_BOOKING, 		"预订房态图中每行显示的房间数量");
//		a(configs, Key.LINE_CAPACITY_RECEPTION, 	"接待房态图中每行显示的房间数量");
//		a(configs, Key.NIGHT_AUDIT_TIME, 	"夜审时间(hh:mm)");
//		a(configs, Key.CARD_CONFIG, 		"读卡器的相关配置");
		return configs;
	}
	
	private static void a(List<String[]> o, String key, String value, String desc, boolean single) {
		o.add(new String[] {key, value, desc, String.valueOf(single)});
	}
	
}
